import * as CONSTANT from "@/store/constant.js";
import api from '@/api/index.js'

// 作者
export const getAuthorArticlesAction = (username, page) => {

    return async (dispatch) => {
        const response = await api.authorarticle.getAuthorArticles(username, page)

        if (response && response.status !== 1) {
            throw new Error(response.message)
        }
        const {count, articles} = response.data
        dispatch({type: CONSTANT.ARTICLES_SYNC, payload: {count, articles, currentPage: page}})
    }

}

// 喜欢
export const getFavoriteArticlesAction = (username, page) => {

    return async (dispatch) => {
        const response = await api.authorarticle.getFavoriteArticles(username, page)

        if (response && response.status !== 1) {
            throw new Error(response.message)
        }

        const {count, articles} = response.data
        dispatch({type: CONSTANT.ARTICLES_SYNC, payload: {count, articles, currentPage: page}})
    }

}
